<?php
/***
 * 描述：店铺管理人员登录页面
 * @category		Mobile		
 * @package			Action			
 * @subpackage		
 * @author			wanght <whtaok@gmail.com>
 * @since			2013-4-6
 * @version			$Id: IndexAction.class.php 5 2013-10-14 03:20:14Z whtaok@gmail.com $
 */
class IndexAction extends Action {
	
	/**
	 * 描述：初始化模块
	 * @access		protected
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-4-14
	 */
	protected  function _initialize() {
		ini_set('session.cookie_domain', 'herowind77.vicp.cc');
	}
	/**
	 * 描述：登录页面
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	public function indexAct() {
		if(session('shop_user_id')){
			$this->redirect('OrderManage/index',array('order_status'=>1));
		}else{
			$this->display('login');
		}
		
	}

	/**
	 * 描述：登录操作
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	public function doLoginAct() {
		if ($_POST) {
			$user_name = $_POST['user_name'] && trim($_POST['user_name']) ? trim($_POST['user_name']) : '';
			$user_pass = $_POST['user_pass'] && trim($_POST['user_pass']) ? trim($_POST['user_pass']) : '';
			if (!$user_name || !$user_pass) {
				$this->display(U('login'));
			}
			//生成认证条件
			$mod=new ShopUserModel();
			// 支持使用绑定帐号登录
			$modWhere['account'] = $user_name;
			$shopUser=$mod->where($modWhere)->find();
	
			//使用用户名、密码和状态的方式进行认证
			if(false === $shopUser) {
				$this->error('用户信息不存在！');
			}else {
				if($shopUser['password'] != md5($user_pass)) {
					$this->error('密码输入错误！');
				}
	
				if($shopUser['is_valid'] == 1) {
					$this->error('您的帐号正在审核中，请耐心等待！');
				}
				if($shopUser['is_valid'] == 3) {
					$this->error('您的账号已被禁用，如有问题请联系客服人员！');
				}
	
				//$_SESSION['supplyer_info'] =$supplyer_info;
				$this->mysession_refresh($shopUser['id']);
				$this->success('帐号登录成功！',U('OrderManage/index'),1);
				exit;
			}
		}else{
			$this->display('login');
		}
	}
	private function mysession_refresh($userId){
		//用户信息
		$mod = new ShopUserModel();
		$detailShopUser = $mod->find($userId);
	
		$user = array(
				'account'=>$detailShopUser['account'],
				'mobile'=>$detailShopUser['mobile'],
				'role_name'=>$detailShopUser['role_name'],
				'name'=>$detailShopUser['name'],
				'sex'=>$detailShopUser['sex'],
				'logo'=>$detailShopUser['logo'],
		);
		//店铺信息
		$mod = new ShopLibModel();
		$detailShopLib = $mod->find($detailShopUser['shop_id']);
	
		$shop = array(
				'name'=>$detailShopLib['name'],
				'title'=>$detailShopLib['title'],
				'address'=>$detailShopLib['address'],
				'link_man'=>$detailShopLib['link_man'],
				'link_way'=>$detailShopLib['link_way'],
				'code'=>$detailShopLib['code'],
		);
		session('svc_user_id',$userId);
		session('svc_shop_id',$detailShopUser['shop_id']);
		session('svc_user',$user);
		session('svc_shop',$shop);
	}
	
	/**
	 * 描述：登出操作
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	public function doLogoutAct() {
		session(null);
		$this->display('login');
	}
}

?>